package com.love.marriage.generator.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.love.marriage.common.vo.Result;
import com.love.marriage.common.vo.ResultBoolean;
import com.love.marriage.generator.service.GeneratorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * description:  generator控制器
 * author:       majf
 * createDate:   2022/10/11 14:44
 * version:      1.0.0
 */
@ApiSort(10)
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/generator")
@Tag(name = "generator接口", description = "generator")
public class GeneratorController {

    private final GeneratorService generatorService;

    @ApiOperationSupport(order = 1, author = "alex")
    @GetMapping
    @Operation( method = "GET",summary = "自动生成", description = "自动生成代码")
    @Parameters({
            @Parameter(description = "java路径名称", name = "javaPathName", example = "用户管理"),
            @Parameter(description = "java路径", name = "javaPath", example = "userInfo"),
            @Parameter(description = "表格列表", name = "tableNames", example = "user_info_t"),
            @Parameter(description = "表格列表名称", name = "tableNameInfo", example = "用户管理"),
            @Parameter(description = "作者", name = "author", example = "alex", required = false)})
    @ApiResponse(responseCode = "200", description = "刪除菜单管理表成功",
            content = @Content(schema = @Schema(implementation = ResultBoolean.class)))
    public Result<Boolean> generate(@RequestParam(value = "javaPathName") String javaPathName,
                                    @RequestParam(value = "javaPath") String javaPath,
                                    @RequestParam(value = "tableNames") String[] tableNames,
                                    @RequestParam(value = "tableNameInfo") String[] tableNameInfo,
                                    @RequestParam(value = "author", required = false) String author) throws Exception {
        return Result.success(generatorService.generator(javaPathName, javaPath, tableNames, tableNameInfo, author));
    }
}
